<?php
include_once('config.php');
include_once('ips.php');

$tag = stripslashes($_GET['tag']);
$sour = unserialize($tag);

if(getInstall($sour['domain']) && checkDns($sour,$ips)){
	echo "pass";
}else{
	echo "refuse";
}

function getInstall($domain) {
	$link = mysql_connect(Config::$db_host, Config::$db_user, Config::$db_pass) or die("Link database error!");
	mysql_select_db(Config::$db_name);
	$sql = "select count(*) as num from licence where domain='".mysql_real_escape_string($domain)."'";
	$query = mysql_query($sql,$link);
	$arr = mysql_fetch_array($query, MYSQL_ASSOC);
	if($arr['num'] <= 0){
		return false;
	}else{
		return true;
	}	
}
function checkDns($dnsRecord,$ips){
	$client = gethostbyname($dnsRecord['domain']);
	if(in_array($client,ips)){//at self sitestar server
		return true;
	}
	if(!in_array($client,$dnsRecord) && in_array('127.0.0.1',$dnsRecord)){
		return false;
	}else{
		return true;
	}
}
?>